package com.dji.activationDemo.messaging;

import com.dji.activationDemo.Constant;
import com.dji.activationDemo.uitls.CallbackHandlers;
import com.dji.activationDemo.websocket.WsManager;

import dji.common.error.DJIError;
import dji.common.mission.hotpoint.HotpointHeading;
import dji.common.mission.hotpoint.HotpointMission;
import dji.common.mission.hotpoint.HotpointStartPoint;
import dji.common.model.LocationCoordinate2D;
import dji.common.util.CommonCallbacks;
import dji.sdk.mission.MissionControl;
import dji.sdk.mission.hotpoint.HotpointMissionOperator;
import dji.sdk.remotecontroller.L;

public class HotpointMissionOperatorRes {

    private String sign;
    private HotpointMissionOperator hotpointMissionOperator = MissionControl.getInstance().getHotpointMissionOperator();


    //暂停
    public void pauseHotpointMission(String sign) {
        hotpointMissionOperator.pause(new CommonCallbacks.CompletionCallback() {
            @Override
            public void onResult(DJIError djiError) {
                if (djiError != null) {
                    WsManager.ws.sendText("error*" + sign + "*" + djiError.getDescription());
                } else {
                    WsManager.ws.sendText("received*" + sign);
                }
            }
        });
    }

    //恢复
    public void resumeHotpointMission(String sign) {
        hotpointMissionOperator.resume(new CommonCallbacks.CompletionCallback() {
            @Override
            public void onResult(DJIError djiError) {
                if (djiError != null) {
                    WsManager.ws.sendText("error*" + sign + "*" + djiError.getDescription());
                } else {
                    WsManager.ws.sendText("received*" + sign);
                }
            }
        });
    }

    //停止
    public void stopHotpointMission(String sign) {
        hotpointMissionOperator.stop(new CommonCallbacks.CompletionCallback() {
            @Override
            public void onResult(DJIError djiError) {
                if (djiError != null) {
                    WsManager.ws.sendText("error*" + sign + "*" + djiError.getDescription());
                } else {
                    WsManager.ws.sendText("received*" + sign);
                }
            }
        });
    }


    public void startHotpointMission(String paramString, String sign) {
        this.sign = sign;
        HotpointMission hotpointMission = createHotpointMission(paramString);
        hotpointMissionOperator.startMission(hotpointMission, new CommonCallbacks.CompletionCallback() {
            @Override
            public void onResult(DJIError djiError) {
                if (djiError != null) {
                    WsManager.ws.sendText("error*" + sign + "*加载任务失败：" + djiError.getDescription());
                } else {
                    WsManager.ws.sendText("received*" + sign);
                }
            }
        });
    }


    private HotpointMission createHotpointMission(String paramString) {
        HotpointMission hotpointMission = new HotpointMission();

        //设置热点
        LocationCoordinate2D locationCoordinate2D = new LocationCoordinate2D(31, 121);
        hotpointMission.setHotpoint(locationCoordinate2D);
        /**
         *
         NORTH	Start from the North.
         SOUTH	Start from the South.
         WEST	Start from the West.
         EAST	Start from the East.
         NEAREST	Start the circle surrounding the hotpoint at the nearest point on the circle to the aircraft's current location.
         */
        hotpointMission.setStartPoint(HotpointStartPoint.NEAREST);//在圆上距离飞机当前位置最近的点开始围绕热点的圆。
        /**
         * ALONG_CIRCLE_LOOKING_FORWARDS	航向是沿着圆形路径前进的方向。
         * ALONG_CIRCLE_LOOKING_BACKWARDS	航向是沿圆形路径向后行驶。
         * TOWARDS_HOT_POINT	航向是朝向热点。
         * AWAY_FROM_HOT_POINT	飞机的航向正在远离热点。它是在从热点到飞机定义的向量的方向上。
         * CONTROLLED_BY_REMOTE_CONTROLLER	航向由遥控器控制。
         * USING_INITIAL_HEADING	航向与任务开始时飞机的航向保持一致。
         */
        hotpointMission.setHeading(HotpointHeading.TOWARDS_HOT_POINT);
        hotpointMission.setAltitude(5.0);//高度 double
        hotpointMission.setRadius(5.0);//半径 double
        hotpointMission.setAngularVelocity(3); //角速度 float
        hotpointMission.setClockwise(true);//顺时针

        return hotpointMission;
    }
}
